package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo3.dto.BMIbmi;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class BMIController {
    @GetMapping("/bmi")
    @ResponseBody
    public String bmi(BMIbmi bmii) {
        System.out.println("bmiDTO="+bmii);
        double height = bmii.getHeight();
        double weight = bmii.getWeight();

        double bmi = weight / (height * height);
        {
            if (bmi < 18.5) {
                System.out.println("过轻");
                return "过轻";
            } else if (bmi < 24.9) {
                System.out.println("正常");
                return "正常";
            } else if (bmi < 29.9) {
                System.out.println("过重");
                return "过重";
            } else {
                System.out.println("肥胖");
                return "肥胖";
            }

        }
    }

    @GetMapping("/bmi2/{height}/{weight}")
    @ResponseBody


    public String bmi2(@PathVariable double height, @PathVariable double weight) {



        double bmi = weight / (height * height);
        {
            if (bmi < 18.5) {
                System.out.println("过轻");
                return "过轻";
            } else if (bmi < 24.9) {
                System.out.println("正常");
                return "正常";
            } else if (bmi < 29.9) {
                System.out.println("过重");
                return "过重";
            } else {
                System.out.println("肥胖");
                return "肥胖";
            }

        }
    }
}
